﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RearLivestock.Common.Domains.hhx;
using RearLivestock.Common.Domains.wbx;
using RearLivestock.Common.Dtos;
using RearLivestock.RBAC.Api.Application.wbxApplication.Commands.Role;
using RearLivestock.RBAC.Api.Application.wbxApplication.Commands.User;

namespace RearLivestock.RBAC.Api.Controllers.wbx
{
    /// <summary>
    /// 用户角色控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RolesController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">mediator</param>
        public RolesController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 角色添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddRoles(AddRoleCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 角色显示
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result<PageResultDto<Roles>>> SearchRoles(SearchRoleCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 个人信息反填
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result<Users>> SearchUsers(SearchUserCommand cmd)
        {
            return await mediator.Send(cmd);
        }
    }
}
